package org.smoozik.app.mode.generator;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import org.smoozik.app.ihm.Constants;

public class GeneratorListener implements ActionListener {
	GeneratorMode mode;

	public GeneratorListener(GeneratorMode mode) {
		super();
		this.mode = mode;
	}

	public void actionPerformed(ActionEvent e) {
		mode.getPanel().requestFocusInWindow();

		Object source = e.getSource();
		if (source instanceof JButton) {
			JButton button = (JButton) source;
			String labelButton = button.getText();
			if (Constants.PLAY_LABEL.equals(labelButton)) {
				mode.start();
			} else if (Constants.STOP_LABEL.equals(labelButton)) {
				mode.stopTimer();
			} else if (Constants.REPLAY_LABEL.equals(labelButton)) {
				mode.playFigure();
			} else if (Constants.RESET_LABEL.equals(labelButton)) {
				mode.resteNotes();
			} else if (Constants.PLUS_LABEL.equals(labelButton)) {
				mode.increaseSpeed();
			} else if (Constants.MINUS_LABEL.equals(labelButton)) {
				mode.decreaseSpeed();
			} 
		}
	}

}
